package game;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent;

public class NovoRecorde extends Scene
{
	Background background;
	int pontos;
	SelecaoMenu selecao;
	String nome = "TLOS";
	boolean spaceClicado;
	int maxLetras = 10;
	Font font = new Font("Courier", Font.BOLD, 28);
	int centerX = 354;
	FontMetrics fm;
	
	
	float time;
	
	public NovoRecorde()
	{
		
		//this.font = LoadFonte.getFonte(0);
		this.background = new Background(11);
		
		
		Point[] pos = new Point[29];
		int c = 0;
		for (int i = 0; i < 10; i++) 
		{
			for (int j = 0; j < 3; j++) 
			{
				if(c != 29)
					pos[c] = new Point(569 + (int)(j * 67.5f),
							195 + (int)(i * 37.4f));
				c++;
			}
		}
		selecao = new SelecaoMenu(pos, new Point(32, 18), 3, 10);
	}
	
	public void update()
	{
		
		
		time += Time.getInstance().getLoopTime();
		if(time >= 0.6)
			time = 0;
		this.selecao.update();
		
		if(Keyboard.getInstance().isKeyPressed(KeyEvent.VK_SPACE))
		{
			
			
			if(spaceClicado == false)
			{
				spaceClicado = true;
				
				if(this.selecao.getIndexOpcao() == 27)
				{
					if(nome.length() > 0)
						nome = nome.substring(0, nome.length() -1);
				}
				else if(this.selecao.getIndexOpcao() == 28)
				{
					//BancoRecordes.getInstance().SalvarPontuacao(nome, Congrats.pontuacao);
					SceneManager.changeScene(15);
				}
				else
				{
					if(nome.length() < this.maxLetras)
						this.nome += VerificarTecla();
				}
				
			}
		}
		else
		{
			spaceClicado = false;
		}
		
	}
	
	public void draw(Graphics2D g2d)
	{
		this.background.draw(g2d);
		selecao.draw(g2d);
		
		g2d.setFont(font);
		g2d.setColor(Color.GRAY);
		fm = g2d.getFontMetrics();
		
		g2d.drawString(nome, this.centerX - fm.stringWidth(nome)*0.5f, 345);
		
	}
	
	
	
	public String VerificarTecla()
	{
		String x = "";
		
		switch (this.selecao.getIndexOpcao()) 
		{
			case 0:
				x = "A";
				break;
			case 1:
				x = "B";
				break;
			case 2:
				x = "C";
				break;
			case 3:
				x = "D";
				break;
			case 4:
				x = "E";
				break;
			case 5:
				x = "F";
				break;
			case 6:
				x = "G";
				break;
			case 7:
				x = "H";
				break;
			case 8:
				x = "I";
				break;
			case 9:
				x = "J";
				break;
			case 10:
				x = "K";
				break;
			case 11:
				x = "L";
				break;
			case 12:
				x = "M";
				break;
			case 13:
				x = "N";
				break;
			case 14:
				x = "O";
				break;
			case 15:
				x = "P";
				break;
			case 16:
				x = "Q";
				break;
			case 17:
				x = "R";
				break;
			case 18:
				x = "S";
				break;
			case 19:
				x = "T";
				break;
			case 20:
				x = "U";
				break;
			case 21:
				x = "V";
				break;
			case 22:
				x = "W";
				break;
			case 23:
				x = "X";
				break;
			case 24:
				x = "Y";
				break;
			case 25:
				x = "Z";
				break;
			case 26:
				if(nome.length() > 0)
					if(nome.substring(nome.length() - 1).compareTo( " ") != 0)
						x = " ";
				break;
		}
		
		return x;
	}
	
	
}
